package br.com.roteador.localizacao;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.inject.Named;

import br.com.roteador.persistence.MongoDBDAO;
import br.com.roteador.persistence.MongoDBUtil;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;

@Named("localizacaoMondoDAO")
public class LocalizacaoMongoDAO extends MongoDBDAO {
	    
    public LocalizacaoMongoDAO(){
        super();
    }
    
    public DBCursor getLocalizacoes(){
        BasicDBObject query=new BasicDBObject();
        query.put("parent", "none");
        DBCursor find = this.getDbCollection().find(query);
        return find;
    }
    
    public Boolean insertLocalizacoes(String latitude, String longitude, String imei){
        BasicDBObject query=new BasicDBObject();
        DBCollection db = MongoDBUtil.getCollection("localizacao");
        this.setDbCollection(db);
        query.put("latitude", latitude);
        query.put("longitude", longitude);
        query.put("imei", imei);
        Date date = new Date();
        String newString = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date);
        query.put("datahora", newString);
        this.insert(query);
        return true;
    }
    
}
